package com.guaoran.interview.in2018.bean;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
 * @author : guaoran
 * @Description : <br/>
 * @date :2018/12/21 13:59
 */
public class User implements Serializable {
    private static final long serialVersionUID = -5516373562185274644L;
    private String name;
    //表示不能序列化，writeObject，readObject 就可以进行序列化
    private transient int age;
    public User() {
    }

    public User(String name,int age) {
        this.name = name;
        this.age = age;
    }

    //通过这样就可以进行序列化
    private void writeObject(ObjectOutputStream out) throws IOException{
        out.defaultWriteObject();
        out.writeObject(age);
    }
    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
        in.defaultReadObject();
        age = (int) in.readObject();
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
